package ${file.pkg_this};

import java.util.List;

import com.specter.mvc.model.Page;
import com.specter.mvc.model.Request;
import com.specter.mvc.model.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import ${file.pkg_base}.entity.${bean.entityName};
import ${file.pkg_base}.service.${bean.entityName}Service;

/**
 * ${meta.remark!''} ${bean.tableRemark!''} Api
 * 
 * @apiNote ${bean.tableRemark!''}
 * @author ${meta.author!''}
 * @since ${.now?string("yyyy-MM-dd")}
 * @version 1.0
 */
@RestController
public class ${file.file_name} {

	@Autowired
	private ${bean.entityName}Service ${bean.entityName?uncap_first}Service;

	/**
	 * ${bean.tableRemark!''}分页查询
	 * 
	 * @apiNote 分页查询
	 * @param request 查询条件对象 {@link ${file.pkg_base}.entity.${bean.entityName} 条件Map}
	 * @return 查询结果 {@link com.specter.mvc.model.Page 分页}
	 */
	@RequestMapping
	public Response page(@RequestBody Request request) {
		Page<?> page = ${bean.entityName?uncap_first}Service.page(request);
		return Response.success().data(page);
	}

	/**
	 * ${bean.tableRemark!''}主键查询
	 * 
	 * @apiNote 主键查询
	 * @param id 对象主键
	 * @return 单一对象结果 {@link ${file.pkg_base}.entity.${bean.entityName}}
	 */
	@RequestMapping
	public Response view(String id) {
		${bean.entityName} entity = ${bean.entityName?uncap_first}Service.get(id);
		return Response.success().data(entity);
	}

	/**
	 * ${bean.tableRemark!''}新增或修改，Id为空新增/非空时修改；
	 * 
	 * @apiNote 新增修改
	 * @param entity 对象数据
	 * @return 修改后对象，新增时含Id {@link ${file.pkg_base}.entity.${bean.entityName}}
	 */
	@RequestMapping
	public Response save(@RequestBody ${bean.entityName} entity) {
		entity = ${bean.entityName?uncap_first}Service.save(entity);
		return Response.success().data(entity);
	}

	/**
	 * ${bean.tableRemark!''}按主键删除
	 * 
	 * @apiNote 按主键删除
	 * @param id 对象主键
	 * @return 删除结果消息
	 */
	@RequestMapping
	public Response delete(String id) {
		${bean.entityName?uncap_first}Service.delete(id);
		return Response.success();
	}

	/**
	 * ${bean.tableRemark!''} 按照条件导出
	 * 
	 * @apiNote 按照条件导出
	 * @param request 导出条件对象 {@link ${file.pkg_base}.entity.${bean.entityName}}
	 * @return 导出xlsx
	 */
	@RequestMapping
	public ModelAndView exp(@RequestBody Request request) {
		return ${bean.entityName?uncap_first}Service.exp(request);
	}

	/**
	 * ${bean.tableRemark!''} 按照一定结构数据导入
	 * 
	 * @apiNote 数据导入
	 * @param file 导入文件流
	 * @return 导入成功列表 {@link ${file.pkg_base}.entity.${bean.entityName} 成功List}
	 */
	@RequestMapping
	public Response imp(MultipartFile file) throws Exception {
		List<?> list = ${bean.entityName?uncap_first}Service.imp(file.getInputStream());
		// 此处还要修改，list应该存放问题数据
		return Response.success().data(list);
	}

}
